<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>用户信息查询管理页</title>
</head>

<body>
<?php
//role_assignments

//一、PHP文件引用
require_once 'response.php';
require_once 'connect_config.php';

//二、变量参数定义
$i = 0;
$msg = '';
$$roleid = array();
$rolename = array();
$username = $_GET['username'];
$role = "";

//三、数据库连接、操作
$conn = mysqli_connect(DB_HOST,DB_USER,DB_PWD,DB_NAME,DB_PORT) or die('数据库连接失败');
$query1 = "select * from mdl_user where username = '$username'";
$data1 = mysqli_query($conn, $query1);
if ($data1)
{
	$row1 = mysqli_fetch_array($data1);
	$firstname = $row1['firstname'];
	$lastname = $row1['lastname'];
	$password = $row1['password'];
	$email = $row1['email'];
	$country = $row1['country'];
	$city = $row1['city'];
	$userid = $row1['id'];
	$query2 = "select * from mdl_role_assignments where userid = '$userid'";
	$data2 = mysqli_query($conn, $query2);
	if($data2)
	{
		while($row2 = mysqli_fetch_array($data2))
		{
			$roleid[$i] = $row2['roleid'];
			if($roleid[$i] == 1)
			{
				$rolename[$i] = 'manager';
			}
			else if($roleid[$i] == 2)
			{
				$rolename[$i] = 'coursecreator';
			}
			else if($roleid[$i] == 3)
			{
				$rolename[$i] = 'editingteacher';
			}
			else if($roleid[$i] == 4)
			{
				$rolename[$i] = 'teacher';
			}
			else if($roleid[$i] == 5)
			{
				$rolename[$i] = 'student';
			}
			else if($roleid[$i] == 6)
			{
				$rolename[$i] = 'guest';
			}
			else if($roleid[$i] == 76)
			{
				$rolename[$i] = 'user';
			}
			else 
			{
				$rolename[$i] = 'frontpage';
			}
			//$role = $role."<br>".$rolename[$i];
			$i++;
		}
		
	}
	else
	{
		$status = false;
		$msg = '用户角色查询失败';	
	}
}
else
{
	$status = false;
	$msg = '用户名查询失败';
	$valuse = array($status,$msg);
}
mysqli_close($conn);
echo Response::json($status,$msg,$rolename);
?>
</body>
</html>